/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package avenue;

import customers.ListClientForm;
import javax.persistence.EntityManager;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import model.AppUser;
import model.DBManager;
import model.Station;
import program.ListProgramForm;
import roles.ListRolesForm;
import tolls.CollectTollForm;
import tolls.PaymentForm;
import users.ListUsersForm;

/**
 *
 * @author Aggelos
 */
public class Avenue extends javax.swing.JFrame {
    private final EntityManager em;
    public static AppUser logedUser;    //vV Δημιουργία μεταβλητής για να 
                                        // χρησιμοποιηθεί σαν πέρασμα σε άλλες
                                        // φόρμες της εφαρμογής. 

    /**
     * Creates new form Avenue
     */
    public Avenue() {        
        em = DBManager.em;
        if ( !em.getTransaction().isActive()){
            em.getTransaction().begin();
        }
//vV        LoginForm lf = new LoginForm(this);     //vV Σταματά πλέον η φόρμα
//vV        lf.setVisible(true);                    // Avenue να καλεί την φόρμα Login
                                                    // Πλέον αρχική φόρμα της
                                                    // εφαρμογής γίνεται η Avenue     

        initComponents();        
    }
    
    
    //vV Δημιουργία ενός Constructor με παράμετρο lUser (Log in User), η οποία θα
    // καλείται από την φόρμα Login    
    public Avenue(AppUser lUser) {
        em = DBManager.em;
        if ( !em.getTransaction().isActive()){
            em.getTransaction().begin();
        }
        logedUser = lUser;
        initComponents();
    }

    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        station2 = station1;
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jAppUsersMenuItem3 = new javax.swing.JMenuItem();
        jClientsMenuItem1 = new javax.swing.JMenuItem();
        jRolesMenuItem7 = new javax.swing.JMenuItem();
        jProgramsMenuItem8 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jCollectTollMenuItem2 = new javax.swing.JMenuItem();
        jPaymentMenuItem4 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jCardLogMenuItem5 = new javax.swing.JMenuItem();
        jClientLogMenuItem6 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setLocationByPlatform(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel1.setText("Σταθμός: ");

        jTextField1.setEditable(false);
        jTextField1.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        jTextField1.setBorder(null);
        jTextField1.setEnabled(false);
        jTextField1.setOpaque(false);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, station2, org.jdesktop.beansbinding.ELProperty.create("${description}"), jTextField1, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Χρήστης: ");

        jTextField2.setEditable(false);
        jTextField2.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        jTextField2.setText("");
        jTextField2.setBorder(null);
        jTextField2.setEnabled(false);
        jTextField2.setOpaque(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1)
                .addGap(250, 250, 250)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jTextField1.setText(logedUser.getStationId().getDescription());
        jTextField2.setText(" " + logedUser.getLName() + "  " + logedUser.getFName());

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/avenue/resources/Lanes Gray.PNG"))); // NOI18N
        jLabel3.setText("jLabel3");

        jMenu1.setText("Διαχείριση");

        jAppUsersMenuItem3.setText("Χρήστες");
        jAppUsersMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAppUsersMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jAppUsersMenuItem3);

        jClientsMenuItem1.setText("Πελάτες");
        jClientsMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jClientsMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jClientsMenuItem1);

        jRolesMenuItem7.setText("Ρόλοι");
        jRolesMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRolesMenuItem7ActionPerformed(evt);
            }
        });
        jMenu1.add(jRolesMenuItem7);

        jProgramsMenuItem8.setText("Προγράμματα");
        jProgramsMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jProgramsMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jProgramsMenuItem8);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("Διόδια");

        jCollectTollMenuItem2.setText("Διέλευση");
        jCollectTollMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCollectTollMenuItem2ActionPerformed(evt);
            }
        });
        jMenu3.add(jCollectTollMenuItem2);

        jPaymentMenuItem4.setText("Πληρωμές");
        jPaymentMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPaymentMenuItem4ActionPerformed(evt);
            }
        });
        jMenu3.add(jPaymentMenuItem4);

        jMenuBar1.add(jMenu3);

        jMenu4.setText("Κινήσεις");

        jCardLogMenuItem5.setText("Κίνηση Κάρτας");
        jMenu4.add(jCardLogMenuItem5);

        jClientLogMenuItem6.setText("Κίνηση Πελάτη");
        jMenu4.add(jClientLogMenuItem6);

        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);
        jMenuBar1.getAccessibleContext().setAccessibleName("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 782, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jPaymentMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPaymentMenuItem4ActionPerformed
        // TODO add your handling code here:
        PaymentForm pf = new PaymentForm();
        pf.setVisible(true);
    }//GEN-LAST:event_jPaymentMenuItem4ActionPerformed

    private void jClientsMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jClientsMenuItem1ActionPerformed
        // TODO add your handling code here:
        ListClientForm lcf = new ListClientForm();
        lcf.setVisible(true);
    }//GEN-LAST:event_jClientsMenuItem1ActionPerformed

    private void jAppUsersMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAppUsersMenuItem3ActionPerformed
        // TODO add your handling code here:
        ListUsersForm luf = new ListUsersForm();
        luf.setVisible(true);
    }//GEN-LAST:event_jAppUsersMenuItem3ActionPerformed

    private void jRolesMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRolesMenuItem7ActionPerformed
        // TODO add your handling code here:
        ListRolesForm lrf = new ListRolesForm();
        lrf.setVisible(true);
    }//GEN-LAST:event_jRolesMenuItem7ActionPerformed

    private void jCollectTollMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCollectTollMenuItem2ActionPerformed
        // TODO add your handling code here:
        CollectTollForm ctf = new CollectTollForm();
        ctf.setVisible(true);
    }//GEN-LAST:event_jCollectTollMenuItem2ActionPerformed

    private void jProgramsMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jProgramsMenuItem8ActionPerformed
        // TODO add your handling code here:
        ListProgramForm lpf = new ListProgramForm();
        lpf.setVisible(true);
    }//GEN-LAST:event_jProgramsMenuItem8ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Avenue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Avenue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Avenue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Avenue.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {                
                new Avenue().setVisible(true);                
            }
        });
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem jAppUsersMenuItem3;
    private javax.swing.JMenuItem jCardLogMenuItem5;
    private javax.swing.JMenuItem jClientLogMenuItem6;
    private javax.swing.JMenuItem jClientsMenuItem1;
    private javax.swing.JMenuItem jCollectTollMenuItem2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JMenuItem jPaymentMenuItem4;
    private javax.swing.JMenuItem jProgramsMenuItem8;
    private javax.swing.JMenuItem jRolesMenuItem7;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private model.Station station2;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
     
    Station station1; //vV 
    
    
    public JMenuItem getjMenuItem1() {
        return jClientsMenuItem1;
    }

    public void setjMenuItem1(JMenuItem jMenuItem1) {
        this.jClientsMenuItem1 = jMenuItem1;
    }

    public JMenuItem getjMenuItem2() {
        return jCollectTollMenuItem2;
    }

    public void setjMenuItem2(JMenuItem jMenuItem2) {
        this.jCollectTollMenuItem2 = jMenuItem2;
    }

    public JMenuItem getjMenuItem3() {
        return jAppUsersMenuItem3;
    }

    public void setjMenuItem3(JMenuItem jMenuItem3) {
        this.jAppUsersMenuItem3 = jMenuItem3;
    }

    public JMenuItem getjMenuItem4() {
        return jPaymentMenuItem4;
    }

    public void setjMenuItem4(JMenuItem jMenuItem4) {
        this.jPaymentMenuItem4 = jMenuItem4;
    }

    public JMenuItem getjMenuItem5() {
        return jCardLogMenuItem5;
    }

    public void setjMenuItem5(JMenuItem jMenuItem5) {
        this.jCardLogMenuItem5 = jMenuItem5;
    }

    public JMenuItem getjMenuItem6() {
        return jClientLogMenuItem6;
    }

    public void setjMenuItem6(JMenuItem jMenuItem6) {
        this.jClientLogMenuItem6 = jMenuItem6;
    }

    public JMenuItem getjMenuItem7() {
        return jRolesMenuItem7;
    }

    public void setjMenuItem7(JMenuItem jMenuItem7) {
        this.jRolesMenuItem7 = jMenuItem7;
    }

    public JMenuItem getjMenuItem8() {
        return jProgramsMenuItem8;
    }

    public void setjMenuItem8(JMenuItem jMenuItem8) {
        this.jProgramsMenuItem8 = jMenuItem8;
    }

    
}
